<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Coupon extends Model
{
    use HasFactory;
    
    protected $guarded = ['id'];
    
    public function getMerchantIdsAttribute($value)
    {
        // 假设字段中存储的是以逗号分隔的ID字符串
        $value = str_replace("[","",$value);
        $value = str_replace("]","",$value);
         $value = str_replace('"',"",$value);
        

        return explode(',', $value);
       
    }

     public function setMerchantIdsAttribute($value)
    {
        // 假设字段中存储的是以逗号分隔的ID字符串

        if(empty($value)){

             return "";
        }else{
             $this->attributes['merchant_ids'] = json_encode($value);
        }
       
    }
    public function couponRecord()
    {
        return $this->hasMany(couponRecord::class,'coupon_id','id');
    }
    

}
